/*
 * Copyright (C) 2008 Esmertec AG.
 * Copyright (C) 2008 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.mms.model;

import java.util.ArrayList;

import android.content.ContentResolver;

import com.android.mms.ContentRestrictionException;
import com.android.mms.ExceedMessageSizeException;
import com.android.mms.ResolutionException;
import com.android.mms.UnsupportContentTypeException;
import com.google.android.mms.ContentType;

public class CarrierContentRestriction implements ContentRestriction {

	public static final int IMAGE_HEIGHT_LIMIT = 480;
	public static final int IMAGE_WIDTH_LIMIT = 640;
	public static final int MESSAGE_SIZE_LIMIT = 307200;

	private static final ArrayList<String> sSupportedImageTypes;
	private static final ArrayList<String> sSupportedAudioTypes;
	private static final ArrayList<String> sSupportedVideoTypes;

	static {
		sSupportedImageTypes = ContentType.getImageTypes();
		sSupportedAudioTypes = ContentType.getAudioTypes();
		sSupportedVideoTypes = ContentType.getVideoTypes();
	}

	public void checkAudioContentType(String contentType) throws ContentRestrictionException {
		if (null == contentType) {
			throw new ContentRestrictionException("Null content type to be check");
		}
		if (!sSupportedAudioTypes.contains(contentType)) {
			throw new UnsupportContentTypeException("Unsupported audio content type : " + contentType);
		}
	}

	public void checkVideoContentType(String contentType) throws ContentRestrictionException {
		if (null == contentType) {
			throw new ContentRestrictionException("Null content type to be check");
		}
		if (!sSupportedVideoTypes.contains(contentType)) {
			throw new UnsupportContentTypeException("Unsupported video content type : " + contentType);
		}
	}

	public void checkImageContentType(String contentType) throws ContentRestrictionException {
		if (null == contentType) {
			throw new ContentRestrictionException("Null content type to be check");
		}
		if (!sSupportedImageTypes.contains(contentType)) {
			throw new UnsupportContentTypeException("Unsupported image content type : " + contentType);
		}
	}

	public void checkMessageSize(int messageSize, int increaseSize, ContentResolver resolver)
			throws ContentRestrictionException {
		if ((messageSize < 0) || (increaseSize < 0)) {
			throw new ContentRestrictionException("Negative message size" + " or increase size");
		}
		int newSize = messageSize + increaseSize;
		if ((newSize < 0) || (newSize > 307200)) {
			throw new ExceedMessageSizeException("Exceed message size limitation");
		}
	}

	public void checkResolution(int var1, int var2) throws ContentRestrictionException {
		if (var1 > 640 || var2 > 480) {
			throw new ResolutionException("content resolution exceeds restriction.");
		}
	}

}
